package
{
	import flash.desktop.NativeApplication;
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.display.StageDisplayState;
	import flash.events.Event;
	import flash.events.KeyboardEvent;
	import flash.ui.Keyboard;
	import flash.utils.setTimeout;
	import org.tuio.*;
	import org.tuio.legacy.TUIOManager;
	
	import k3.event.KEvent;
	import ka.KeepAlive;
	
	import udp.UdpManager;
	
	public class TUIOAS extends Sprite
	{
		private var tuioManager:org.tuio.legacy.TUIOManager;
		
		public function TUIOAS()
		{
			
			var ka1:KeepAlive=new KeepAlive();
			ka1.active();
			this.addChild(ka1);
			stage.color=0xffffff;
			stage.align="tl";
			stage.scaleMode="noScale";
			this.stage.displayState=StageDisplayState.FULL_SCREEN;
			setTimeout(init,1000);
			
		}
		
		private function init():void
		{
			tuioManager=new TUIOManager();
			this.addChild(tuioManager);
			stage.nativeWindow.addEventListener(Event.CLOSE,handleExit);
			stage.addEventListener(KeyboardEvent.KEY_UP,handleKeyUp);
			
			
			UdpManager.init("127.0.0.1",3334);
			
		}
		
		private function handleKeyUp(e:KeyboardEvent):void
		{
			if(e.keyCode==Keyboard.ESCAPE)
			{
				stage.nativeWindow.close();
			}
		}
		
		private function handleExit(e:Event):void
		{
			trace("handleExit");
			if(tuioManager)
			{
				tuioManager.close();
				
				tuioManager=null;
			}
			
				UdpManager.gc();
			
			
		}
		
		//点击
		/*
		Lag of 54.375 sek
		480 528
		addTuioCursor
		handleAdd
		updateTuioCursor
		handleUpdate
		updateTouchReceiver
		updateTouchReceiver
		removeTuioCursor
		handleRemove
		*/
		
		/*
		addTuioObject
		updateTuioObject
		updateTuioObject
		updateTuioObject
		updateTuioObject
		updateTuioObject
		updateTuioObject
		updateTuioObject
		updateTuioObject
		updateTuioObject
		updateTuioObject
		updateTuioObject
		removeTuioObject

		*/
	}
}